home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / pm-utils / hdparm-functions < prev    next >
Text File  |  2009-10-06  |  3KB  |  92 lines

  1. #!/bin/sh
  2.  
  3. hdparm_is_on_battery() {
  4.     on_ac_power 2>/dev/null
  5.     [ $? -eq 1 ]
  6. }
  7.  
  8. # query /etc/hdparm.conf for the apm (-B) option to use for the named
  9. # drive, taking into account system defaults and current AC power status,
  10. # and return the numeric value on standard out
  11. # arguments: devicename, in traditional /dev/sd? format
  12. # output: numeric value suitable for passing to hdparm -B
  13. # returns: 0, or causes the caller to exit non-zero on parse error
  14. hdparm_apm_option_for_disk()
  15. {
  16.     local WANTED_DISK="$1"
  17.     local DISC=
  18.     local OPTION=
  19.     local DEFAULT=
  20.  
  21.     egrep -v '^[[:space:]]*(#|$)' /etc/hdparm.conf | 
  22.     {
  23.         while read KEY SEP VALUE; do
  24.             case $SEP in
  25.                 '{')
  26.                     case $KEY in
  27.                         *)
  28.                             DISC=$KEY
  29.                             ;;
  30.                     esac
  31.                     ;;
  32.                 =)
  33.                     case $KEY in
  34.                         apm)
  35.                             if ! hdparm_is_on_battery; then
  36.                                 if [ "$WANTED_DISK" = "$DISC" ]; then
  37.                                     OPTION="$VALUE"
  38.                                 elif [ -z "$DISC" ]; then
  39.                                     DEFAULT="$VALUE"
  40.                                 fi
  41.                             fi
  42.                             ;;
  43.                         apm_battery)
  44.                             if hdparm_is_on_battery; then
  45.                                 if [ "$WANTED_DISK" = "$DISC" ]; then
  46.                                     OPTION="$VALUE"
  47.                                 elif [ -z "$DISC" ]; then
  48.                                     DEFAULT="$VALUE"
  49.                                 fi
  50.                             fi
  51.                             ;;
  52.                         *)
  53.                             # ignore.
  54.                             ;;
  55.                     esac
  56.                     ;;
  57.                 "")
  58.                     case $KEY in
  59.                         '}')
  60.                             if [ -z "$DISC" ]; then
  61.                                 log "hdparm-functions: No disk enabled. Exiting"
  62.                                 exit 1
  63.                             fi
  64.                             ;;
  65.                         quiet|standby|sleep|disable_seagate|security_freeze)
  66.                             ;;
  67.                         *)
  68.                             log "unknown option $KEY"
  69.                             exit 1
  70.                             ;;
  71.                     esac
  72.                     ;;
  73.                 *)
  74.                     log "unknown separator $SEP"
  75.                     exit 1
  76.                     ;;
  77.             esac
  78.         done
  79.         if [ -z "$OPTION" ]; then
  80.             OPTION="$DEFAULT"
  81.         fi
  82.         if [ -z "$OPTION" ]; then
  83.             if hdparm_is_on_battery; then
  84.                 OPTION="128"
  85.             else
  86.                 OPTION="254"
  87.             fi
  88.         fi
  89.         echo $OPTION
  90.     }
  91. }
  92.